package com.ojoin.trade.common.web.dao.impl;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.RoleDao;
import com.ojoin.trade.common.web.domain.Role;

@Repository
public class RoleDaoImpl extends BaseDaoImpl<Role> implements RoleDao {

	public SqlSession getSqlSession() {
		return this.sqlSessionTemplate;
	}
	
	
	@Override
	public Role getByName(Role role) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		Role ret;
		try {
			ret = this.sqlSessionTemplate.selectOne(getSqlName(mapMethodName),role);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ret;
	}

	@Override
	public Role getByEnname(Role role) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		Role ret;
		try {
			ret = this.sqlSessionTemplate.selectOne(getSqlName(mapMethodName),role);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ret;
	}

	@Override
	public int deleteRoleMenu(Role role) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.delete(getSqlName(mapMethodName),role);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}

	@Override
	public int deleteRoleButton(Role role) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.delete(getSqlName(mapMethodName),role);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}

	@Override
	public int deleteRoleOffice(Role role) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.delete(getSqlName(mapMethodName),role);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}

	@Override
	public int insertRoleMenu(Role role) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.insert(getSqlName(mapMethodName),role);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}
	
	@Override
	public int insertRoleButton(Role role) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.insert(getSqlName(mapMethodName),role);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}
	
	@Override
	public int insertRoleOffice(Role role) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.insert(getSqlName(mapMethodName),role);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}
	

}
